<!DOCTYPE html>
<html>
<head>
    <title>user form</title>
    <#include "/header.html">
    <style>
        .layui-upload-img {
            max-height: 100px;
        }
    </style>
</head>
<body class="bg-white">

<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <input type="hidden" name="avatar" value="">
                <div class="layui-upload">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="uploadPreview" src="${request.contextPath}/statics/images/avatar.png">
                        <p id="uploadText"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="mobile" value="18888888888" class="layui-input layui-disabled" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="输入昵称" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="gender" value="1" title="男">
                <input type="radio" name="gender" value="2" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">启用</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="" name="status" value="1" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
        </div>

        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div> -->
    </form>
</div>

<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form,
            $ = layui.$;

        var _parent = parent;
        if (_parent.formDataId > 0) {
            $.ajax({
                type: "POST",
                url: serverUrl('userextra/info/' + _parent.formDataId),
                data: {},
                dataType: "json",
                success: function (result) {
                    if (result.code === 0) {
                        form.val('dataForm', result.info);
                        if (result.info.avatar != '') {
                            $('#uploadPreview').attr('src', result.info.avatar);
                        }
                    }
                }
            });
        }

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var params = data.field;
            params['id'] = _parent.formDataId
            submitFormData('userextra/update', params);
            return false;
        });

    });
</script>
</body>
</html>